package com.nuedu.corejava.ch13;

import java.util.Random;

/**
 * <pre>
 *     线程开发步骤2
 *         1.编写一个类实现java.lang.Runnable接口 
 *         2.实现run方法
 *         3.运行一个线程
 *         4.Runnable 接口经常用于内部类编程；
 * 
 * </pre>
 * 
 * @author admin
 *
 */

public class ThreadDemo2 implements Runnable {
	private int count = 0;

	@Override
	public void run() {
		while (count <= 10) {
			try {
				Thread.sleep(new Random().nextInt(2000));
				System.out.println(count++);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		ThreadDemo2 demo2 = new ThreadDemo2();
		// demo2.start;//注意：实现Runnable接口没有start方法；
		Thread thread = new Thread(demo2);// 需要把Runnable实现类包装成Thread类的对象才能执行start方法
		thread.start();

	}

}
